home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / vmed.arc / VMED10.CCC < prev    next >
Text File  |  1985-12-03  |  5KB  |  180 lines

  1. /*
  2.  * VMED10/CCC
  3.  *    virtual memory interface to ED2 editor
  4.  *
  5.  *    made from Ed Ream's ED10 module
  6.  *
  7.  *         created:    November 25, 1983 - Jim Kyle
  8.  *         changed:    February 29, 1984 - Jim Kyle
  9.  *    last changed:    March 3-9, 1984 - Jim Kyle
  10.  */
  11.  
  12. /* data global to this module (must precede #includes)*/
  13.  
  14. char    bufcflag;    /* main buffer changed flag */
  15.  
  16. #include vm                /* gets ED defs also */
  17. /*    #include vmtrace    /* --comment out unless debugging */
  18. t_r()    {}                /* --comment out if debugging */
  19.  
  20. /* Clear the main buffer */
  21. bufnew()        /* go_top() call moved 3/3/84 */
  22. {    vm_init();        /* initialize work file, etc. */
  23.     bufins(0,0);    /* set in null line for EOF */
  24.     go_top();        /* position to top of work file */
  25. /* indicate no need to save file yet */
  26.     bufcflag = NO;
  27. }
  28.  
  29. /* Insert a line before the current line.
  30.  * p points to a line of length n to be inserted.
  31.  * Note: n does not include trailing CR.
  32.  */
  33. bufins(p,n)    char *p;    int n;
  34. {    char temp[MAXLEN2];
  35.     t_r("bufins");
  36.     n = min(n,MAXLEN);
  37.     vm_move(p,temp+2,n);            /* move text */
  38.     n += 2;                /* include size in the count */
  39.     putwd(n,temp);                    /* move it in */
  40.     if (Cur_ln > Lltf)    /* 3-8-84 at EOF just add it */
  41.         ins_btm(temp);
  42.     else    {
  43.         open_hole(n);                /* make room */
  44.         cpy_in(temp,clad(),n);
  45.     }
  46.     bufcflag = YES;            /* mark file as changed */
  47.     return(OK);
  48. }
  49.  
  50. /* delete the current line */
  51. bufdel()
  52. {    return(bufdeln(1));    }
  53.  
  54. /* delete n lines, starting with the current line */
  55. bufdeln(n)    int n;
  56. {    if (at_eof()) return(OK);    /* 3-8-84 do nothing */
  57.     vm_abt(n < 0, "bufdeln");
  58.     while (n-- && in_txt())    {        /* 3-8-84 */
  59.         while (Cur_ln > Llcb)
  60.             go_nxb();
  61.         if (at_eof())    break;        /* 3-7-84 */
  62.         else    {    
  63.             ln_del(clad());
  64.             if (*Lcptr == 0 && Curr)    /* dump empty */
  65.                 rel_blk(Curr);
  66.         }
  67.     }
  68.     bufcflag = YES;
  69.     return(OK);
  70. }
  71.  
  72. /* replace current line with the line that
  73.  * p points to.  The new line is of length n.
  74.  */
  75. bufrepl(p,n)    char *p;    int n;
  76. {    return(bufdel()==OK ? bufins(p,n) : ERR);    }
  77.  
  78. /* copy current line into buffer that p points to.
  79.  * the maximum size of that buffer is n.
  80.  * return k = length of line in the main buffer.
  81.  * if k > n then truncate n - k characters and only
  82.  * return n characters in the caller's buffer.
  83.  */
  84. bufgetln(p,n)    char *p;    int n;
  85. {    int    k;
  86. /* last line is always null */
  87.     if (past_eof()) {        /* 3/8/84 - jk */
  88.         *p = EOS;
  89.         return(0);
  90.     }
  91. /* copy line as long as it is not too long */
  92.     k = getwd(clad()) - 2;
  93.     vm_move(clad()+2,p,min(k,n));
  94.     *(p + min(k,n)) = EOS;
  95.     return(k);
  96. }
  97.  
  98. /* return current line number */
  99. bufln()
  100. {    return(Cur_ln);    }
  101.  
  102. /* return YES if the buffer (i.e.. file) has been
  103.  * changed since the last time the file was saved.
  104.  */
  105. bufchng()
  106. {    return(bufcflag);    }
  107.  
  108. /* the file has been saved. clear bufcflag */
  109. bufsaved()
  110. {    bufcflag = NO;    }
  111.  
  112. /* return number of lines in the file (excluding null EOF) */
  113. buffree()
  114. {    return(Lltf-1);    }    /* 3/8/84 - jk */
  115.  
  116. /* position buffer pointers to start of indicated line */
  117. bufgo(line)    int line;        /* all new, 3/3/84 */
  118. {    line = max(0, min(line, buffree()));
  119.     return(go_to(line));
  120. }
  121.  
  122. /* move one line closer to front of buffer, i.e., set
  123.  * buffer pointers to start of previous line.
  124.  */
  125. bufup()
  126. {    return(go_pvl());    }
  127.  
  128. /* Move one line closer to end of buffer, i.e.,
  129.  * set buffer pointers to start of next line.
  130.  */
  131. bufdn()               
  132. {    return(past_eof() ? OK : go_nxl());    }    /* 3-9-84 */
  133.  
  134. /* return true if at bottom of buffer.        /* 3-8-84 */
  135. past_eof()
  136. {    return(Cur_ln >= Lltf);    }
  137.  
  138. /* return true if at last text line */
  139. at_eof()
  140. {    return(Cur_ln == Lltf-1);    }    /* 3-7-84 - jk */
  141.  
  142. /* return true if within text limits
  143.  * (line > 0 and < Lltf) - added 3-8-84 jk
  144.  */
  145. in_txt()
  146. {    return(Cur_ln < Lltf && Cur_ln > 0);    }
  147.  
  148. /* return true if at top of buffer */
  149. bufattop()
  150. {    return(Cur_ln < 2);    }
  151.  
  152. /* put nlines from buffer starting with line topline at
  153.  * position topy of the screen.
  154.  */
  155. bufout(topline,topy,nlines)    int topline,topy,nlines;
  156. {    int    l;
  157. /* remember buffer's state */
  158.     l = Cur_ln;
  159. /* write out one line at a time */
  160.     while ((nlines--) > 0)    {
  161.         outxy(0,topy++);
  162.         bufoutln(topline++);
  163.     }
  164. /* restore buffer's state */
  165.     go_to(l);
  166. }
  167.  
  168. /* print line of main buffer on screen */
  169. bufoutln(line)    int line;
  170. {    char temp[MAXLEN2];
  171.     go_to(line);
  172.     if (in_txt())    {            /* 3-8-84 */
  173.         bufgetln(temp,MAXLEN2);
  174.         fmtsout(temp, 0);
  175.     }
  176.     outdeol();
  177. }
  178.  
  179. /* end module vmed10/ccc */
  180.